const navList = document.querySelector('.shortcut .fr ul')
function setupMenuInteraction() {
  // 获取所有带有下拉菜单的项
  const menuItems = navList.querySelectorAll('li.arrow-icon')
  menuItems.forEach(item => {
    const menu = item.querySelector('.menu')
    // 鼠标移入
    item.addEventListener('mouseenter', () => {
      menu.style.display = 'block'
      menu.style.opacity = 1
    })
    // 鼠标移出
    item.addEventListener('mouseleave', () => {
      menu.style.opacity = 0
      menu.style.display = 'none'
    })
  })
}
document.addEventListener('DOMContentLoaded', setupMenuInteraction)

//显示用户信息
const login = document.querySelector('.shortcut .fl ul .sc a')
const register = login.nextElementSibling
function renderUname() {
  const currentUser = JSON.parse(localStorage.getItem('currentUser'))
  if (currentUser) {
    login.innerHTML = `<a href="javascript:;"><i class="icon-user"></i> ${currentUser.uname}</a>`
    register.innerHTML = '<a href="javascript:;">退出登录</a>'
  } else {
    login.innerHTML = '<a href="./login.html" class="style_red">请先登录</a>'
    register.innerHTML = '<a href="register.html">免费注册</a>'
  }
}
renderUname()

//退出登录
register.addEventListener('click', () => {
  localStorage.removeItem('currentUser')
  renderUname()
})

